﻿-- =============================================
-- Author:		<Author,XFL>
-- Create date: <Create Date,20111227>
-- Description:	<Description,通过单位编号 查找 用户对应的权限信息>
--		根据单位编号查询角色数据
--				if(@InType=0) 通过旧单位编号查询新单位编号
--				if(@InType=1) 直接使用新单位编号
--		查询所有的角色数据
--				if(@InType=2) 查询全部数据 与单位无关
-- =============================================
CREATE PROCEDURE [dbo].[proc_NetUser_For_RolesList]
	-- Add the parameters for the stored procedure here
(
@InType int,
@DWBH varchar(20)
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering ;WITH SELECT statements.
	SET NOCOUNT ON;
	Declare @IsExists varchar(20)
if(@InType=0)
begin 
	Select  @IsExists=[dwbh] From [Company] where [Id]=@DWBH
end
else
if(@InType=1)
begin 
	Set @IsExists=@DWBH
end
if(@InType=2)    
begin 
	SELECT 
		R.[ID] as [ID]
		,ISNULL(R.[Mid],'---') as [Mid]
		,ISNULL(R.[Cid],'---') as [Cid]
		,ISNULL(R.[Did],'---') as [Did]
		,ISNULL(R.[RName],'---') as [RName]
		,ISNULL(R.[EntryPeople],'---') as [EntryPeople]
		,R.[EntryTime] as [EntryTime]
		,ISNULL(R.[RNote] ,'---') as [RNote]
		,FAdminFlg
	From [App_Roles] R   order by RName
end
ELSE
BEGIN
 	SELECT 
		R.[ID] as [ID]
		,ISNULL(R.[Mid],'---') as [Mid]
		,ISNULL(R.[Cid],'---') as [Cid]
		,ISNULL(R.[Did],'---') as [Did]
		,ISNULL(R.[RName],'---') as [RName]
		,ISNULL(R.[EntryPeople],'---') as [EntryPeople]
		,R.[EntryTime] as [EntryTime]
		,ISNULL(R.[RNote] ,'---') as [RNote]
		,FAdminFlg

	From [App_Roles] R
    Where R.[Cid] like '%[[]'+@IsExists+']%'
       order by RName
END
END


return
